package WZL.newba;

/**
 *随机生成真分数题目的类
 *
 */
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class properFraction {
    //    public static void main(String[] args) {
    public properFraction(int x){
        String answer = null;
        int M,Z;
        ArrayList<String> sz = new ArrayList<String>(x);
        String daan[]=new String [x];
        int x1,x2,m1,m2;
        for(int i=0;i<x;i++){
            m1=1+(int)(Math.random()*10);//随机生成一个小于10的分母
            x1=1+(int)(Math.random()*m1);//生成一个比分母小的分子，实现真分数
            m2=1+(int)(Math.random()*10);//随机生成一个小于10的分母
            x2=1+(int)(Math.random()*m2);//生成一个比分母小的分子，实现真分数
            int op=(int)(Math.random()*3);//生成运算符

            Fenshujisuan r1 = new Fenshujisuan(x1,m1);
            Fenshujisuan r2 = new Fenshujisuan(x2,m2);
            Fenshujisuan r3,r4,r5,r6;
            if(op==0){
                answer = r3;
                String a = x1+"/"+m1+" + "+x2+"/"+m2+"=       ";
//                 System.out.print(a);
                sz.add(a);
            }
            if(op==1){
                answer = r4;
                String b  = x1+"/"+m1+" - "+x2+"/"+m2+"=       ";
//                 System.out.print(b);
                sz.add(b);
            }
            if(op==2){
                answer = r5;
                String c  = x1+"/"+m1+" * "+x2+"/"+m2+"=       ";
//                 System.out.print(c);
                sz.add(c);
            }
            if(op==3){
                answer = r6;
                String d  = x1+"/"+m1+" / "+x2+"/"+m2+"=       ";
//                 System.out.print(d);
                sz.add(d);
            }

            daan[i]=answer;

        }
        int wrong = 0;
        for(int i = 0;i<sz.size();i++){
            System.out.println(sz.get(i));
            System.out.print("输入答案: ");
            Scanner scan = new Scanner(System.in);
            String udaan = scan.nextLine();
            if(!udaan.equals(daan[i])){
                System.out.println("错误    正确答案为："+daan[i]);
                System.out.println(" ");
                wrong = wrong+1;
            }
            else {
                System.out.println("正确");
                System.out.println(" ");
            }
        }
        int sum=100-(wrong*100/x);
        System.out.println("正确率："+sum+"%");
    }


    public static String yuefen(int a,int b){
        int y = 1;
        for(int i=a;i>=1;i--){
            if(a%i==0&&b%i==0){
                y = i;
                break;
            }
        }
        int z = a/y;
        int m = b/y;
        if(z==0) {
            return"0";
        }
        return""+z+"/"+m;
    }

    public void fs() {

    }
}

